package com.nabi.library.contents.elements
{
	import com.nabi.library.contents.elements.style.SolidFill;
	import com.nabi.library.contents.elements.style.SolidStroke;
	import com.nabi.library.contents.elements.style.Style;
	import com.nabi.library.contents.geom.ITransform;
	import com.nabi.library.utility.Drawer;
	
	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.sampler.NewObjectSample;
	
	public class NabiObject extends Sprite
	{
		protected var m_points:Vector.<Vector.<Number>>;
		protected var m_outlineList:Vector.<Outline>;
		protected var m_style:Style;
		
		protected var m_matrix:Matrix;
		protected var m_transform:ITransform;
		
		protected var m_x:Number;
		protected var m_y:Number;
		protected var m_width:Number;
		protected var m_height:Number;
		protected var m_rotation:Number;
		
		public function NabiObject($outlineList:Vector.<Outline> = null)
		{
			if($outlineList == null) $outlineList = new Vector.<Outline>();
			init();
			SetOutlineList($outlineList);
		}
		
		private function init(): void
		{
			blendMode = BlendMode.LAYER;
			m_x = m_y = 0;
			m_width = m_height = 0;
			m_style = new Style(new SolidFill(), new SolidStroke());
			m_points = new Vector.<Vector.<Number>>();
		}
		
		public function Redraw(): void
		{
			var transMatrix:Matrix;
			if(m_transform) transMatrix = m_transform.GetTransformMatrix();
			var innerOutlineStyle:Style = new Style(new SolidFill(-1), new SolidStroke());
			
			graphics.clear();
			Drawer.Draw(graphics, m_outlineList[0], m_style, transMatrix);
			for(var i:int = 1; i < m_outlineList.length; ++i)
			{
				Drawer.Draw(graphics, m_outlineList[i], innerOutlineStyle, transMatrix);
			}
		}
		
		public function GetOutlineList(): Vector.<Outline> { return m_outlineList; }
		
		public function SetOutlineList($outlineList:Vector.<Outline>): void
		{
			m_points.length = 0;
			m_outlineList = $outlineList;
			for each(var outline:Outline in m_outlineList)
			{
				m_points.push(outline.GetPoints());
			}
		}
		
		public function GetTransform(): ITransform { return m_transform; }
		
		public function SetTransform($transform:ITransform): void
		{
			m_transform = $transform;
			Redraw();
		}
		
		public function GetStyle(): Style { return m_style; }
		
		public function SetStyle($style:Style): void
		{
			m_style = $style;
			Redraw();
		}
	}
}